<!DOCTYPE html>
{% load static %}
{% load i18n %}
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{% trans "wuhuanfengyue" %}</title>
    <link rel="stylesheet" href="{% static "bootstrap-3.3.7/css/bootstrap.css" %}">
    <script src="{% static "js/jquery-3.3.1.min.js" %}"></script>
    <script src="{% static "bootstrap-3.3.7/js/bootstrap.js" %}"></script>
    {% block script %}{% endblock %}
</head>
<body>
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand" href="{% url 'index' %}">{% trans 'wuhuanfengyue' %}</a>
        </div>
        <form class="navbar-form navbar-left">
            <div class="form-group">
            <input class="form-control" placeholder="Search">
            </div>
        </form>
        <ul class="nav navbar-nav navbar-right">
            {% for m in MENU %}
            {% if m.children %}
                <li class="dropdown">
                    <a href="{{ m.url }}"  class="dropdown-toggle" id="{{ m.name }}" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                        {{ m.name }}<span class="caret"></span>
                    </a>
                <ul class="dropdown-menu" aria-labelledby="{{ m.name }}">
                {% for child in m.children %}
                    <li><a href="{{ child.url }}">{{ child.name }}</a></li>
                {% endfor %}
                </ul>
                </li>
            {% else %}
                <li {% if m.url == request.path %} class='active' {% endif %}><a href="{{ m.url }}">{{ m.name }}</a></li>
            {% endif %}
            {% endfor %}
            {% get_current_language as LANGUAGE_CODE %}
            {% get_available_languages as LANGUAGES %}
            <li class="dropdown">
                    <a class="dropdown-toggle" id="language_switch" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{{ LANGUAGE_CODE|language_name_translated }}</a>
            <ul class="dropdown-menu" aria-labelledby="language_switch">
                {% for l in LANGUAGES %}
                <li><a class="language" code="{{ l.0 }}">{{ l.1 }}</a></li>
                {% endfor %}
            </ul>
            </li>
        </ul>
    </div>
</nav>
{#tags#}

{% block content %}
{% endblock %}
</body>
</html>
<script>
    $('.language').click(function(){
        console.log($(this).attr('code'))
        $.ajax({
            url: '{% url "set_language" %}',
            type: 'POST',
            data: {
                "language": $(this).attr('code')
            },
            success: function(){
                window.location.reload()
            }   
        })
    })
</script>